package com.realtyManage.springboot.Dao;


import com.realtyManage.springboot.Model.Do.ApplyInfo;
import com.realtyManage.springboot.Model.Do.ApplyRule;
import com.realtyManage.springboot.Model.Do.Area;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.Date;

/**
 * 报备规则
 * @author 杭州素色网络科技有限公司
 * @since 2019-12-24
 */

@Repository
public interface ApplyRuleRepository extends JpaRepository<ApplyRule, Integer>, JpaSpecificationExecutor<ApplyRule> {

    @Modifying
    @Transactional
    @Query("update ApplyRule a set " +
            "a.bbDetail =  CASE WHEN :#{#applyRule.bbDetail} IS NULL THEN a.bbDetail ELSE :#{#applyRule.bbDetail} END, " +
            "a.bhDetail =  CASE WHEN :#{#applyRule.bhDetail} IS NULL THEN a.bhDetail ELSE :#{#applyRule.bhDetail} END, " +
            "a.jyDetail =  CASE WHEN :#{#applyRule.jyDetail} IS NULL THEN a.jyDetail ELSE :#{#applyRule.jyDetail} END, " +
            "a.zcDetail =  CASE WHEN :#{#applyRule.zcDetail} IS NULL THEN a.zcDetail ELSE :#{#applyRule.zcDetail} END, " +
            "a.qhNum =  CASE WHEN :#{#applyRule.qhNum} IS NULL THEN a.qhNum ELSE :#{#applyRule.qhNum} END, " +
            "a.fqhNum =  CASE WHEN :#{#applyRule.fqhNum} IS NULL THEN a.fqhNum ELSE :#{#applyRule.fqhNum} END, " +
            "a.fqfNum =  CASE WHEN :#{#applyRule.fqfNum} IS NULL THEN a.fqfNum ELSE :#{#applyRule.fqfNum} END, " +
            "a.userId =  CASE WHEN :#{#applyRule.userId} IS NULL THEN a.userId ELSE :#{#applyRule.userId} END, " +
            "a.userName =  CASE WHEN :#{#applyRule.userName} IS NULL THEN a.userName ELSE :#{#applyRule.userName} END, " +
            "a.infoTime =  CASE WHEN :#{#applyRule.infoTime} IS NULL THEN a.infoTime ELSE :#{#applyRule.infoTime} END " +
            "where a.id = :#{#applyRule.id}")
    int updateApplyRule(@Param("applyRule") ApplyRule applyRule);

    /*@Query(value = "select apply_detail from apply_rule where type = ?1",nativeQuery = true)
    int queryApplyRuleByType(Integer b);*/

    @Query(value = "select * from apply_rule",nativeQuery = true)
    ApplyRule queryApplyRule();
}

